package com.example.anote;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ProgressBar;

public class NoteAdapter extends ArrayAdapter<NoteList> {
	
	 private ArrayList<NoteList> items;
	 
	 public NoteAdapter(Context context, int textViewResourceId, ArrayList<NoteList> items) {
         super(context, textViewResourceId, items);
         this.items = items;
 }

 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
         View v = convertView;
         if (v == null) {
             LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             v = vi.inflate(R.layout.affichageitem, null);
         }
         NoteList o = items.get(position);
         if (o != null) {
                 TextView titre = (TextView) v.findViewById(R.id.titre);
                 ProgressBar progress = (ProgressBar) v.findViewById(R.id.progressBar);
                 ImageView imgview = (ImageView) v.findViewById(R.id.img_note);
                
                 if (titre != null) {
                	 titre.setText(o.getTitre());  }
                 if (progress != null) {
                	 progress.setProgress(o.getProgress());  }
                 if (progress != null) {
                	 progress.setProgress(o.getProgress());  }
                 if (imgview != null) {
                	 if (o.getStat()==0)
                	 {
                		 imgview.setImageResource(R.drawable.default_icon);
                	 }
                	 if (o.getStat()==1)
                	 {
                		 imgview.setImageResource(R.drawable.info);
                	 }
                	 if (o.getStat()==2)
                	 {
                		 imgview.setImageResource(R.drawable.warning);
                	 }
                	
                 }
                 
                 } 
                
         return v;


}
}
